/**
 * Copyright (c) 2011 Axa Holding Belgium, SA. All rights reserved.
 * This software is the confidential and proprietary information of the AXA Group.
 */
package chabernac.android.tools;

import java.util.concurrent.Executors;
import java.util.concurrent.ScheduledExecutorService;
import java.util.concurrent.TimeUnit;

public class Timer {
  private long myTimeout;
  private Runnable myAction;
  private ScheduledExecutorService myService = Executors.newScheduledThreadPool( 1 );
  
  public Timer(long aTimeout, Runnable anAction){
    myTimeout = aTimeout;
    myAction = anAction;
  }
  
  public void start(){
    myService.schedule( myAction, myTimeout, TimeUnit.MILLISECONDS);
  }
  
  public void reset(){
    stop();
    myService = Executors.newScheduledThreadPool( 1 );
    start();
  }
  
  public void stop(){
    myService.shutdownNow(); 
  }
}
